package com.ruoyi.web.wx.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.wx.entity.TrashAutonomousRecordDetails;
import com.ruoyi.web.wx.entity.TrashRecordDetails;
import com.ruoyi.web.wx.service.ITrashAutonomousRecordDetailsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 自主投递记录详情 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-27
 */
@Controller
@RequestMapping("/system/trashAutonomousRecordDetails")
public class TrashAutonomousRecordDetailsController extends BaseController
{
    private String prefix = "system/trashAutonomousRecordDetails";
	
	@Autowired
	private ITrashAutonomousRecordDetailsService trashAutonomousRecordDetailsService;
	
	@RequiresPermissions("system:trashAutonomousRecordDetails:view")
	@GetMapping()
	public String trashAutonomousRecordDetails(String taRecordId, ModelMap mmap)
	{

			if (StringUtils.isNotEmpty(taRecordId)){
				mmap.put("taRecordId",taRecordId);
			}
		return prefix + "/trashAutonomousRecordDetails";
	}
	
	/**
	 * 查询自主投递记录详情列表
	 */
	@RequiresPermissions("system:trashAutonomousRecordDetails:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TrashAutonomousRecordDetails trashAutonomousRecordDetails)
	{
		if (trashAutonomousRecordDetails==null||StringUtils.isEmpty(trashAutonomousRecordDetails.getTaRecordId())){
			return getDataTable(new ArrayList<TrashRecordDetails>());
		};
		startPage();
        List<TrashAutonomousRecordDetails> list = trashAutonomousRecordDetailsService.selectTrashAutonomousRecordDetailsList(trashAutonomousRecordDetails);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出自主投递记录详情列表
	 */
	@RequiresPermissions("system:trashAutonomousRecordDetails:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrashAutonomousRecordDetails trashAutonomousRecordDetails)
    {
    	List<TrashAutonomousRecordDetails> list = trashAutonomousRecordDetailsService.selectTrashAutonomousRecordDetailsList(trashAutonomousRecordDetails);
        ExcelUtil<TrashAutonomousRecordDetails> util = new ExcelUtil<TrashAutonomousRecordDetails>(TrashAutonomousRecordDetails.class);
        return util.exportExcel(list, "trashAutonomousRecordDetails");
    }
	
	/**
	 * 新增自主投递记录详情
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存自主投递记录详情
	 */
	@RequiresPermissions("system:trashAutonomousRecordDetails:add")
	@Log(title = "自主投递记录详情", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TrashAutonomousRecordDetails trashAutonomousRecordDetails)
	{		
		return toAjax(trashAutonomousRecordDetailsService.insertTrashAutonomousRecordDetails(trashAutonomousRecordDetails));
	}

	/**
	 * 修改自主投递记录详情
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TrashAutonomousRecordDetails trashAutonomousRecordDetails = trashAutonomousRecordDetailsService.selectTrashAutonomousRecordDetailsById(id);
		mmap.put("trashAutonomousRecordDetails", trashAutonomousRecordDetails);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存自主投递记录详情
	 */
	@RequiresPermissions("system:trashAutonomousRecordDetails:edit")
	@Log(title = "自主投递记录详情", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TrashAutonomousRecordDetails trashAutonomousRecordDetails)
	{		
		return toAjax(trashAutonomousRecordDetailsService.updateTrashAutonomousRecordDetails(trashAutonomousRecordDetails));
	}
	
	/**
	 * 删除自主投递记录详情
	 */
	@RequiresPermissions("system:trashAutonomousRecordDetails:remove")
	@Log(title = "自主投递记录详情", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(trashAutonomousRecordDetailsService.deleteTrashAutonomousRecordDetailsByIds(ids));
	}
	
}
